/*
 * @lc app=leetcode.cn id=852 lang=javascript
 *
 * [852] 山脉数组的峰顶索引
 */

// @lc code=start
/**
 * @param {number[]} arr
 * @return {number}
 */
var peakIndexInMountainArray = function (arr) {
  if (arr.length === 1) return 0;
  if (arr[0] > arr[1]) return 0;
  if (arr[arr.length - 1] > arr[arr.length - 2]) return arr.length - 1;
  let start = 0, end = arr.length - 1;
  while (start <= end) {
    mid = start + (end - start) / 2 >>> 0;
    console.log(arr[mid])
    if (arr[mid] > arr[mid - 1] && arr[mid] > arr[mid + 1]) {
      return mid;
    }
    if (arr[mid] < arr[mid + 1]) {
      start = mid + 1;
    } else {
      end = mid - 1;
    }
  }
};
// @lc code=end
